<template>
    <template v-if="visible">
        <Teleport to="body">
            <div class="zgn-dialog-overlay" @click="close"></div>
            <div class="zgn-dialog-wrapper">
                <div class="zgn-dialog">
                    <header class="zgn-title">
                        <slot name="title"></slot>
                    </header>
                    <main class="zgn-content">
                        <slot name="content"></slot>
                    </main>
                    <footer class="zgn-buttons">
                        <Button purpose="yes" theme="button" @click="ok">确认</Button>
                        <Button purpose="no" theme="button" @click="cancel">取消</Button>
                    </footer>
                    </div> 
                </div> 
        </Teleport>  
    </template>
</template>

<script lang="ts">
import Button from './Button.vue'
export default {
    props:{
        visible:{
            type:Boolean,
            default:false,
        },
        ok:{
            type:Function
        },
        cancel:{
            type:Function
        },
    },
    components:{Button},
    setup(props,ctx){
        const close=()=>{
            ctx.emit('update:visible',false)
        }
        const ok=()=>{
            if(props.ok && props.ok()!== false){
                close()
            }
        }
        const cancel=()=>{
            props.cancel()
            close()
        }
        return {close,ok,cancel}
    },
}
</script>

<style lang="scss" >
.zgn-dialog-overlay{
    position: fixed;
    background: rgba(90, 87, 87, 0.5);
    z-index: 20;
    width: 100vw;
    height: 100vh;
    top: 0;
    right: 0;
}
.zgn-dialog-wrapper{
    position: absolute;
    z-index: 30;
    border-radius: 10px;
    box-shadow: 1px 1px 2px 2px rgb(201, 199, 199);
    background-color: rgba(252, 249, 249, 0.8);
    width: 350px;
    height: 170px;
    top: 20%;
    left:40%;
    padding: 10px;
    >.zgn-dialog{
        display: flex;
        flex-wrap: nowrap;
        flex-direction: column;
        >header{
            font-size: 18px;
            color: black;
            margin-bottom:15px ;
            padding-bottom: 5px;
            border-bottom: 1px solid rgb(179, 176, 176);
        }
        >main{
            display: flex;
            flex-direction: column;
            flex-grow: 2;
            height: 60px;
            padding-left: 10px;
            overflow: auto;
        }
        >footer{
            margin-top: 10px;
            margin-left: 200px; 
        }
    } 
}
@media (max-width:500px) {
.zgn-dialog-wrapper{
    left:10%; 
}
              
}
</style>